home *** CD-ROM | disk | FTP | other *** search
/ Chip 2002 February / CHIPCD_02_2002.iso / Internet / Macromedia ColdFusion Server 5 / coldfusion-50-win-us.exe / data1.cab / Examples / CFDOCS / snippets / queryaddcolumn.cfm < prev    next >
Encoding:
Text File  |  2001-06-13  |  2.1 KB  |  80 lines

  1. <!--- This example shows the use of QueryNew --->
  2.  
  3. <HTML>
  4.  
  5. <HEAD>
  6. <TITLE>
  7. QueryAddColumn Example
  8. </TITLE>
  9. </HEAD>
  10.  
  11. <BASEFONT FACE="Arial, Helvetica" SIZE=2>
  12.  
  13. <BODY  bgcolor="#FFFFD5">
  14.  
  15. <BASEFONT FACE="Arial, Helvetica" SIZE=2>
  16. <BODY  bgcolor="#FFFFD5">
  17.  
  18. <H3>QueryAddColumn Example</H3>
  19.  
  20. <P>This example adds three columns to a query object and then populates 
  21. the columns with the contents of three arrays.</P>  
  22.  
  23. <P>After populating the query, the example shows, in tabular format, the
  24. contents of the columns.</P> 
  25.  
  26. <!--- make a new query --->
  27. <CFSET Employees = QueryNew("")>
  28.  
  29. <!--- create an array --->
  30. <CFSET EmpNamesArray = ArrayNew(1)>
  31. <CFSET EmpNamesArray[1] = "Jane Smith">
  32. <CFSET EmpNamesArray[2] = "Bertrand Russell">
  33. <CFSET EmpNamesArray[3] = "Bronco Horvath">
  34. <CFSET EmpNamesArray[4] = "Angelica Huston">
  35.  
  36. <!--- add a column to the query --->
  37. <CFSET nColumnNumber = QueryAddColumn(Employees, "Name", EmpNamesArray)>
  38.  
  39. <!--- create a second array --->
  40. <CFSET PhoneNoArray = ArrayNew(1)>
  41. <CFSET PhoneNoArray[1] = "617-222-2323">
  42. <CFSET PhoneNoArray[2] = "781-347-4545">
  43. <CFSET PhoneNoArray[3] = "781-348-5565">
  44.  
  45. <!--- add a second column to the query --->
  46. <CFSET nColumnNumber2 = QueryAddColumn(Employees, "PhoneNo", PhoneNoArray)>
  47.  
  48. <!--- create a third array --->
  49. <CFSET LocationArray = ArrayNew(1)>
  50. <CFSET LocationArray[1] = "Santa Barbara">
  51. <CFSET LocationArray[2] = "Boston">
  52. <CFSET LocationArray[3] = "Boston">
  53. <CFSET LocationArray[4] = "Boston">
  54.  
  55. <!--- add a third column to the query --->
  56. <CFSET nColumnNumber3 = QueryAddColumn(Employees, "Location", LocationArray)>
  57.  
  58. <table cellspacing="2" cellpadding="2" border="0">
  59. <tr>
  60.     <th align="left">Name</th>
  61.     <th align="left">Phone</th>
  62.     <th align="left">Location</th>
  63. </tr>
  64. <CFOUTPUT query="Employees">
  65. <tr>
  66.     <td>#Name#</td>
  67.     <td>#PhoneNo#</td>
  68.     <td>#Location#</td>
  69. </tr>
  70. </CFOUTPUT>
  71. </table>
  72.  
  73. <P><B>Note:</B> Because there are fewer elements under Phone than the other columns, 
  74. QueryAddColumn added padding to this column in the query.</P>
  75.  
  76.  
  77. </BODY>
  78.  
  79. </HTML>       
  80.